import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:live_music/components/ui/theme.dart';
import 'package:live_music/models/notification_detail_model.dart';
import 'package:live_music/pages/comment/comment_detail.dart';
import 'package:live_music/pages/detail/moment_detail.dart';
import 'package:live_music/pages/other/click_see_other.dart';
import 'package:live_music/utils/cgq_utils.dart';
import 'package:live_music/utils/contentParse.dart';
import 'package:live_music/utils/util.dart';

class AtAndCommentInfoCard extends StatefulWidget {
  AtAndCommentInfoCard({
    Key key,
    this.index,
    this.notificationItem,
  }) : super(key: key);
  final int index;
  final NotificationDetailModel notificationItem;
  @override
  _AtAndCommentInfoCardState createState() => _AtAndCommentInfoCardState();
}

class _AtAndCommentInfoCardState extends State<AtAndCommentInfoCard>
    with SingleTickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
    print(widget.notificationItem.moment.userAvatarUrl);
  }

  notificationTypeDesc() {
    if (widget.notificationItem.type == "REPOST") {
      return "转发";
    }
    if (widget.notificationItem.type == "AT_ON_COMMENT") {
      return "评论";
    }
    if (widget.notificationItem.type == "AT_ON_CHILDREN_COMMENT") {
      return "评论";
    }
    if (widget.notificationItem.type == "LIKE_MOMENT") {
      return "点赞你的动态";
    }
    if (widget.notificationItem.type == "LIKE_VIDEO") {
      return "点赞你的视频";
    }
    if (widget.notificationItem.type == "COLLECT_VIDEO") {
      return "收藏你的视频";
    }
    if (widget.notificationItem.type == "LIKE_COMMENT") {
      return "点赞你的评论";
    }
    if (widget.notificationItem.type == "LIKE_CHILDREN_COMMENT") {
      return "点赞你的评论";
    }
    if (widget.notificationItem.type == "SHARE_MOMENT") {
      return "分享你的视频";
    }
    if (widget.notificationItem.type == "SHARE_VIDEO") {
      return "分享你的视频";
    }

    return "";
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
        onTap: () => {
              if (notificationTypeDesc().contains("评论") ||
                  widget.notificationItem.type.contains("COMMENT_TO") ||
                  widget.notificationItem.type
                      .contains("REPLY_TO_MOMENT_COMMENT"))
                {
                  Get.to(CommentDetailPage(
                      momentId: widget.notificationItem.momentId,
                      commentId: widget.notificationItem.parentCommentId != 0
                          ? widget.notificationItem.parentCommentId
                          : widget.notificationItem.commentId))
                }
              else
                {Get.to(MomentDetailPage(id: widget.notificationItem.momentId))}
            },
        child: Container(
          margin: const EdgeInsets.only(bottom: 4),
          decoration: BoxDecoration(
              border: Border(
            bottom: BorderSide(width: .5, color: WcaoTheme.outline),
          )),
          child: Padding(
            padding: const EdgeInsets.all(16),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                InkWell(child:SizedBox(
                  width: 44,
                  height: 44,
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(44),
                    child: CgqUtils.imageCache(
                        widget.notificationItem.moment.userAvatarUrl,
                        fit: BoxFit.cover),
                  ),
                ) , onTap: () {
                    Get.to(
                        PageViewOther(userId:widget.notificationItem.moment.userId));
                  }),
                
                Expanded(
                  child: Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 8),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              widget.notificationItem.moment.userName,
                              style: TextStyle(
                                color: WcaoTheme.base,
                                fontWeight: FontWeight.bold,
                                fontSize: WcaoTheme.fsL,
                              ),
                            ),
                            Text(
                              notificationTypeDesc(),
                              style: TextStyle(
                                color: Colors.blueAccent,
                                fontSize: 12,
                              ),
                            ),
                          ],
                        ),
                        Container(
                          margin: const EdgeInsets.only(top: 4),
                          child: Text(
                            getDateTime(widget.notificationItem.createTime),
                            style: TextStyle(
                              color: WcaoTheme.secondary,
                            ),
                          ),
                        ),
                        widget.notificationItem.moment.textContent != null
                            ? Container(
                                margin: const EdgeInsets.only(top: 12),
                                child: FormattedText(
                                  widget.notificationItem.moment.textContent,
                                  style: TextStyle(
                                    color: WcaoTheme.base,
                                  ),
                                  maxLines: 5,
                                  overflow: TextOverflow.ellipsis,
                                ),
                              )
                            : Container(),
                        widget.notificationItem.parentCommentContent != null
                            ? Container(
                                margin: const EdgeInsets.only(top: 4),
                                child: Wrap(
                                  children: [
                                    Text(
                                      "评论你：",
                                      style: TextStyle(
                                        fontSize: 12,
                                        color: Colors.blueAccent,
                                      ),
                                    ),
                                    SizedBox(
                                      width: 2,
                                    ),
                                    Text(
                                      widget.notificationItem
                                          .parentCommentContent,
                                      style: TextStyle(
                                        fontSize: 12,
                                        color: Colors.black,
                                      ),
                                    )
                                  ],
                                ))
                            : Container(),
                        widget.notificationItem.moment.repostedMoment != null
                            ? InkWell(
                                onTap: () => {
                                      Get.to(MomentDetailPage(
                                          id: widget.notificationItem.moment
                                              .repostedMoment.id))
                                    },
                                child: Container(
                                    decoration: BoxDecoration(
                                        color: Colors.grey[200],
                                        borderRadius: BorderRadius.circular(8)),
                                    padding: EdgeInsets.all(8),
                                    margin: EdgeInsets.only(top: 10, bottom: 6),
                                    child: Column(
                                      mainAxisAlignment:
                                          MainAxisAlignment.start,
                                      children: [
                                        widget.notificationItem.category !=
                                                "NOTIFICATION"
                                            ? Row(
                                                children: [
                                                  Text(
                                                      "@" +
                                                          widget
                                                              .notificationItem
                                                              .moment
                                                              .repostedMoment
                                                              .userName,
                                                      style: TextStyle(
                                                        color:
                                                            Colors.blueAccent,
                                                        fontSize: 14,
                                                        fontWeight:
                                                            FontWeight.bold,
                                                      )),
                                                  Text(":",
                                                      style: TextStyle(
                                                        color: Colors.grey,
                                                        fontSize: 14,
                                                        fontWeight:
                                                            FontWeight.bold,
                                                      )),
                                                ],
                                              )
                                            : Container(),
                                        Container(
                                          alignment: Alignment.centerLeft,
                                          margin: EdgeInsets.only(top: 8),
                                          child: FormattedText(
                                            widget.notificationItem.moment
                                                .repostedMoment.textContent,
                                            style: TextStyle(
                                              color: WcaoTheme.base,
                                            ),
                                            maxLines: 5,
                                            overflow: TextOverflow.ellipsis,
                                          ),
                                        ),
                                      ],
                                    )))
                            : Container(
                                decoration: BoxDecoration(
                                    color: Colors.grey[200],
                                    borderRadius: BorderRadius.circular(8)),
                                padding: EdgeInsets.all(8),
                                margin: EdgeInsets.only(top: 10, bottom: 6),
                                child: Column(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    children: [
                                      Container(
                                        alignment: Alignment.centerLeft,
                                        margin: EdgeInsets.only(top: 8),
                                        child: Text(
                                          "原动态已被删除",
                                          style: TextStyle(
                                            color: WcaoTheme.base,
                                          ),
                                        ),
                                      )
                                    ]))
                      ],
                    ),
                  ),
                )
              ],
            ),
          ),
        ));
  }
}
